package org.anddev.andengine.extension.svg.util.texture;

import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureFactory;
import org.anddev.andengine.opengl.texture.TextureManager;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.source.AssetTextureSource;

import android.content.Context;

public class TextureHolder {
	private AssetTextureSource mAssetTextureSource;
	private Texture[] mTextures = new Texture[9];
	
	public TextureHolder(final Context pContext, final String pSource){
		this.mAssetTextureSource = new AssetTextureSource(pContext, pSource);
	}
	
	public void addTexture(final int pTextureOptionIndex, final TextureManager pTextureManager){
		if(this.mTextures[pTextureOptionIndex]==null){
			mTextures[pTextureOptionIndex] = TextureFactory.createForTextureSourceSize(this.mAssetTextureSource, this.getTextureOption(pTextureOptionIndex));
			pTextureManager.loadTexture(mTextures[pTextureOptionIndex]);
		}
	}
	
	public Texture getTexture(final int pTextureOptionIndex){
		return this.mTextures[pTextureOptionIndex];
	}
	
	public TextureOptions getTextureOption(final int pIndex) {
		switch(pIndex){
			case 1:
				return TextureOptions.NEAREST;
			case 2:
				return TextureOptions.BILINEAR;
			case 3:
				return TextureOptions.REPEATING;
			case 4:
				return TextureOptions.REPEATING_BILINEAR;
			case 5:
				return TextureOptions.NEAREST_PREMULTIPLYALPHA;
			case 6:
				return TextureOptions.BILINEAR_PREMULTIPLYALPHA;
			case 7:
				return TextureOptions.REPEATING_PREMULTIPLYALPHA;
			case 8:
				return TextureOptions.REPEATING_BILINEAR_PREMULTIPLYALPHA;
			default:
				return TextureOptions.DEFAULT;
		}
	} 
	
	public AssetTextureSource getAssetTextureSource(){
		return this.mAssetTextureSource;
	}
}
